package com.tianhui.consignortwofei.myview;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.mvp.model.enty.QuoationPaiHaoBean;

import org.yczbj.ycrefreshviewlib.adapter.RecyclerArrayAdapter;
import org.yczbj.ycrefreshviewlib.holder.BaseViewHolder;

/**
 * @author fei
 * @date 2024/1/10
 * @description
 */
public class QuotationSelectAdapter <T> extends RecyclerArrayAdapter<T> {
    private int selectPosition = -1;

    public QuotationSelectAdapter(Context context) {
        super(context);
    }

    public void setSelectPosition(int selectPosition) {
        this.selectPosition = selectPosition;
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new QuotationSelectAdapter.SelectViewHolder(parent, R.layout.item_select_dialog);
    }

    private class SelectViewHolder extends BaseViewHolder<T> {
        private ImageView imageView;
        private TextView textView;

        public SelectViewHolder(ViewGroup parent, int res) {
            super(parent, res);
            imageView = getView(R.id.item_select_dialog_imageView);
            textView = getView(R.id.item_select_dialog_textView);
        }

        @Override
        public void setData(T data) {
            super.setData(data);
            textView.setText(getSelectItemText(data));
            if (selectPosition == getDataPosition()) {
                imageView.setVisibility(View.VISIBLE);
            } else {
                imageView.setVisibility(View.INVISIBLE);
            }
        }

        private String getSelectItemText(T data) {
            if (data == null) {
                return "";
            } else {
                QuoationPaiHaoBean paiHaoBean = (QuoationPaiHaoBean) data;
                return paiHaoBean.getMfrname()+"|"+paiHaoBean.getName()+"|"+paiHaoBean.getProducer();
            }
//                if (data instanceof ISelectItemValue) {
//                ISelectItemValue iSelectItemValue = (ISelectItemValue) data;
//                return iSelectItemValue.getSelectItemText();
//            } else if (data instanceof String) {
//                return data.toString();
//            }else if (data instanceof String) {
//                return data.toString();
//            }
//            return "";
        }
    }

}

